	define(function() {

		var request = {}

		request.Main_Host = "http://192.168.0.78:7091";

		//异步调用 简单方式
		request.OnAjax = function(type, route, data, success_call, err_call, timeout) {
			request.requestAjax(type, route, data, function(res) {
				console.log(JSON.stringify(res))
				if(res.state == true) {
					if(success_call != null) {
						success_call(res.data);
					}
				} else {
					mui.toast(res.error);
					if(err_call != null) {
						err_call(res.code);
					}
				}
			}, function(res) {
				mui.toast("网络错误，请检查网络连接");
				console.log(res.responseText)
				console.log(JSON.stringify(res))
				if(err_call != null) {
					err_call(101);
				}
			}, timeout);
		}

		//异步调用
		request.requestAjax = function(type, route, data, success_call, err_call, timeout, url, dataType, header) {
			require(["tool"], function(tools) {
				if(timeout == null) {
					timeout = 15000;
				}
				if(typeof(data) != 'string') {
					//注入access_token
					if(data != null && data.access_token == null) {
						data.access_token = tools.OnGetAccessToken();
					}

					data = JSON.stringify(data);
				}
				url = request.checkUrl(route, url)

					!header ? header = {
						'Content-Type': 'application/json'
					} : header = {
						'Content-Type': header
					};

				!!route ? url : url = url + type;
				!!dataType ? dataType : dataType = "json";

				!!type ? type : type = "post";

				mui.ajax(url, {
					data: data,
					dataType: dataType, //服务器返回json格式数据
					type: type, //HTTP请求类型
					timeout: timeout, //超时时间设置为10秒；
					headers: header,
					success: success_call,
					error: err_call
				});
			});
		}
		
		request.checkUrl = function(route, url) {
			if(!!url) {
				url = url
			} else {
				url = request.Main_Host + "/recruitserver/api/v1/" + route
			}
			
			return url;
		}
		
		//原生封装，暂时用不到
		request.xhrRequest = function(route, resolve, data, type, url) {
			url = request.checkUrl(route, url);
			console.log(url);
			var xhr = new XMLHttpRequest();
			xhr.onreadystatechange = function() {
				switch(xhr.readyState) {
					case 4:
						plus.nativeUI.closeWaiting();
						if(xhr.status == 200) {

						} else {
							console.log("检测更新失败！");
							plus.nativeUI.alert("检测更新失败！");
						}
						break;
					default:
						break;
				}
			}
			xhr.open('GET', url);
			xhr.send();
		}
		
//		//同步调用 简单方式
//		request.OnAjaxSync = function(type, route, data, resolve, reject, timeout) {
//			request.requestAjaxSync(type, route, data, function(res) {
//				console.log(JSON.stringify(res))
//				if(res.state == true) {
//					if(resolve != null) {
//						resolve(res.data);
//					}
//				} else {
//					mui.toast(res.error);
//					if(reject != null) {
//						reject(res.code);
//					}
//				}
//			}, function(res) {
//				mui.toast("网络错误，请检查网络连接");
//				console.log(res.responseText)
//				console.log(JSON.stringify(res))
//			}, timeout);
//		}
//		//同步调用
//		request.requestAjaxSync = function(type, route, data, resolve, reject, timeout, url, dataType, header) {
//			require(["tool"], function(tools) {
//				if(typeof(data) != 'string') {
//					//注入access_token
//					if(data != null && data.access_token == null) {
//						data.access_token = tools.OnGetAccessToken();
//					}
//					data = JSON.stringify(data);
//				}
//				if(timeout == null) {
//					timeout = 15000;
//				}
//
//				url = request.checkUrl(route, url)
//
//					!header ? header = {
//						'Content-Type': 'application/json'
//					} : header = {
//						'Content-Type': header
//					};
//
//				!!route ? url : url = url + type;
//				!!dataType ? dataType : dataType = "json";
//
//				!!type ? type : type = "post";
//				mui.ajax(url, {
//					async: false,
//					data: data,
//					dataType: dataType, //服务器返回json格式数据
//					type: type, //HTTP请求类型
//					timeout: timeout, //超时时间设置为10秒；
//					headers: header,
//					success: resolve,
//					error: reject
//				});
//			});
//		}


		return request;
	})